function Slide(settings) {
	this.time = settings.time;
	this.speed = settings.speed;
	this.autoStart = (settings.autoStart === "true") ? true : false;
	this.now = 0;
	this.ul = null;
	this.list = null;
	this.prev = null;
	this.next = null;
	this.liNum = 0;
	this.timer = 0
}
Slide.prototype.atCalc = function() {
	if (this.now == this.liNum - 1) {
		this.ul.children().eq(0).css({
			"left": this.width + "px",
			"z-index": 10
		});
		this.ul.children().eq(this.now - 1).css({
			"left": -this.width + "px",
			"z-index": 10
		})
	} else {
		if (this.now == 0) {
			this.ul.children().eq(this.now + 1).css({
				"left": this.width + "px",
				"z-index": 10
			});
			this.ul.children().eq(this.liNum - 1).css({
				"left": -this.width + "px",
				"z-index": 10
			})
		} else {
			this.ul.children().eq(this.now + 1).css({
				"left": this.width + "px",
				"z-index": 10
			});
			this.ul.children().eq(this.now - 1).css({
				"left": -this.width + "px",
				"z-index": 10
			})
		}
	}
};
Slide.prototype.mtCalcR = function() {
	this.ul.children().eq(this.now).css({
		"left": this.width + "px",
		"z-index": 10
	})
};
Slide.prototype.mtCalcL = function() {
	this.ul.children().eq(this.now).css({
		"left": -this.width + "px",
		"z-index": 10
	})
};
Slide.prototype.move = function() {
	var This = this;
	var lock = true;

	function goRight() {
		if (lock) {
			lock = false;
			if (This.now == This.liNum - 1) {
				This.ul.children().eq(This.now).stop().animate({
					"left": -This.width,
					"z-index": 0
				}, This.speed);
				This.ul.children().eq(0).stop().animate({
					"left": 0
				}, This.speed, function() {
					This.now = 0;
					This.list.children().eq(This.now).addClass("active").siblings().removeClass("active");
					This.atCalc();
					lock = true
				})
			} else {
				This.ul.children().eq(This.now).stop().animate({
					"left": -This.width,
					"z-index": 0
				}, This.speed);
				This.ul.children().eq(This.now + 1).stop().animate({
					"left": 0
				}, This.speed, function() {
					This.now++;
					This.list.children().eq(This.now).addClass("active").siblings().removeClass("active");
					This.atCalc();
					lock = true
				})
			}
		}
	}

	function goLeft() {
		if (lock) {
			lock = false;
			if (This.now == 0) {
				This.ul.children().eq(This.now).stop().animate({
					"left": This.width,
					"z-index": 0
				}, This.speed);
				This.ul.children().eq(This.liNum - 1).stop().animate({
					"left": 0
				}, This.speed, function() {
					This.now = This.liNum - 1;
					This.list.children().eq(This.liNum - 1).addClass("active").siblings().removeClass("active");
					This.atCalc();
					lock = true
				})
			} else {
				This.ul.children().eq(This.now).stop().animate({
					"left": This.width,
					"z-index": 0
				}, This.speed);
				This.ul.children().eq(This.now - 1).stop().animate({
					"left": 0
				}, This.speed, function() {
					This.now--;
					This.list.children().eq(This.now).addClass("active").siblings().removeClass("active");
					This.atCalc();
					lock = true
				})
			}
		}
	}
	if (This.autoStart) {
		This.timer = setInterval(goRight, This.time)
	}
	This.list.children().bind("mouseenter", function() {
		if (!lock) {
			return
		}
		var old = This.now;
		var touch = This.list.children().index(this);
		This.now = touch;
		if (touch > old) {
			lock = false;
			This.mtCalcR();
			This.ul.children().eq(old).stop().animate({
				"left": -This.width,
				"z-index": 0
			}, This.speed);
			This.list.children().eq(touch).addClass("active").siblings().removeClass("active");
			This.ul.children().eq(touch).stop().animate({
				"left": 0
			}, This.speed, function() {
				This.atCalc();
				lock = true
			})
		} else {
			if (touch < old) {
				lock = false;
				This.mtCalcL();
				This.ul.children().eq(old).stop().animate({
					"left": This.width,
					"z-index": 0
				}, This.speed);
				This.list.children().eq(touch).addClass("active").siblings().removeClass("active");
				This.ul.children().eq(touch).stop().animate({
					"left": 0
				}, This.speed, function() {
					This.atCalc();
					lock = true
				})
			}
		}
	});
	This.ul.parent().hover(function() {
		if (This.autoStart) {
			clearInterval(This.timer)
		}
		if ($(document).width() > 1430) {
			$(this).children("a").show();
			$(this).children("a.slide-next").animate({
				"right": 40
			}, 300);
			$(this).children("a.slide-prev").animate({
				"left": 40
			}, 300)
		}
	}, function() {
		if (This.autoStart) {
			This.timer = setInterval(goRight, This.time)
		}
		$(this).children("a.slide-next").hide().css("right", "45px");
		$(this).children("a.slide-prev").hide().css("left", "45px")
	});
	This.next.bind("click", function() {
		if (!lock) {
			return
		}
		goRight()
	});
	This.prev.bind("click", function() {
		if (!lock) {
			return
		}
		goLeft()
	})
};
Slide.prototype.init = function(settings) {
	var This = this;
	this.ul = $(settings.imgUl);
	this.list = $(settings.listUl);
	this.prev = $(settings.prevBtn);
	this.next = $(settings.nextBtn);
	this.liNum = this.ul.children().length;
	this.width = $(document.body).width() < 1200 ? 1200 : $(document.body).width();
	if (this.liNum == 0) {
		return
	} else {
		if (this.liNum > 0 && this.liNum < 2) {
			this.ul.children().eq(0).clone().appendTo(this.ul);
			this.ul.children().eq(0).clone().appendTo(this.ul)
		} else {
			if (this.liNum > 1 && this.liNum < 3) {
				this.ul.children().clone().appendTo(this.ul)
			}
		}
	}
	this.liNum = this.ul.children().length;
	this.ul.children().eq(0).css("z-index", 10);
	this.ul.find("img").css("margin-left", (This.width - This.ul.find("img").eq(0).outerWidth()) / 2 + "px");
	for (var i = 0; i < this.liNum; i++) {
		if (i == 0) {
			$('<li class="active"></li>').appendTo(this.list)
		} else {
			$("<li></li>").appendTo(this.list)
		}
	}
	this.atCalc();
	this.move();
	$(window).resize(function() {
		This.width = $(document.body).width() < 1200 ? 1200 : $(document.body).width();
		This.ul.find("img").css("margin-left", (This.width - This.ul.find("img").eq(0).outerWidth()) / 2 + "px");
		This.atCalc()
	})
};